/**
 * 主要是判断启动预案或事件处理
 */
$(document).ready(function () {	
	
	selectPlanLevel();//选择预案的时候转页面
	
	//以下为从事件预案表中load出预案,为页面刚开始就load出来，dgm
	url_queryEventPlan="/ag/dgm/queryEventPlan_DGMdisposalAdvice.action";
	$.post(url_queryEventPlan,{},function(data){
//		alert(data.tbPlan.PId);
		$("#planAdvice").attr("value",data.tbPlan.PId);
		$("#planAdvice").text(data.tbPlan.PName);
	});
	
	//以下为从事件中load出预案标准表的预案标准条目dgm
	url_queryEventPlanStandard="/ag/dgm/queryEventPlanStandard_DGMdisposalAdvice.action";
	$.post(url_queryEventPlanStandard,{},function(data){
		$.each(data.planStandardList,function(i,n){
			$(".planStanderItem").show();
			$(".planStanderItemtext").append("</br></br>"+n.PContent);
//			$(".planStanderItem").after("<tr style='border-bottom:0px'>" +
//					"<td style='border-bottom:0px' height='28' colspan='6' bgcolor='#FFFFFF'>"+
//          "<p><span style='color:#000000;border:0px'>" +
//          n.PContent+
//			  "</span></p></td></tr>");
		});
	});
	
	//以下从事件中load出预案原因dgm
	url_queryPlanReason="/ag/dgm/queryPlanReason_DGMdisposalAdvice.action";
	$.post(url_queryPlanReason,{},function(data){
		if(data.planReason!=null){
			$(".planReason").show();
			$(".planReasontext").append("</br></br>"+data.planReason);
//			$(".planReason").after("<tr><td height='28' colspan='6' bgcolor='#FFFFFF'>"+
//			          "<p><span style='color:#000000;'>" +
//			          data.planReason+
//			 "</span></p></td></tr>");
		}
	});
	
	//以下为删除事件预案dgm
	$("#deletePlan").click(function(){
		url_delPlanByEvent="/ag/dgm/delPlanByEvent_DGMdisposalAdvice.action";
		$.post(url_delPlanByEvent,{},function(data){
			alert(data.result);
			history.go(0);
		});
	});
	
	
	
	//以下为点击当前事件所选预案时的动作，跳到指定的预案页面，dgm
	$("#planAdvice").click(function(){
		var PlanId=$(this).attr("value");
		if(!PlanId||PlanId=="110"){
			alert("未有预案");
		}else{
			window.location.href="/ag/work/queryPlan.jsp?PId="+PlanId;
		}
	});
/*
	findReportTableEnt();
	//alert("dfgdfg");
	$('#sureZhzrm').click(function () {
		setEventPlan2Session();
	});
*/
	$('#startPlanPrm').click(function () {
		//alert("startPlanPrm");
		//checkEmergency();
		window.location.href="/ag/work/rating.jsp";
		/**
		 * 这个用来预案申请用得，需求改变了不用这个
		 */
		//window.location.href="/ag/work/apply4plan1.jsp";
	});
	$('#eventConduct').click(function () {
		//saveToFomalPropose1();
		//window.location.href="/ag/work/zhzrmnoplan.jsp";
		//alert("eventConduct");
		if($('#tbUserByPViceCommander').text()==""){
			alert("请选择指挥长！");
			return;
		}
		directly();
	});
	$('#tyxj').click(function () {
		//window.location.href="/ag/work/zhzrmnoplan.jsp";
		//alert("eventConduct");
		if($('#PComments').val()==""){
			alert("请填写审核意见！");
			return;
		}
		//alert($("input[name='planRadio']:checked").val());
		agreeLower($(this));
	});
});


function directly(){
	//ppId=getCookie(ppId);
	//alert(ppId+"ppId");
	var a=$('#tbUserByPCommander').text();
	var b=$('#tbUserByPViceCommander').text();
	var c=$('#tbUserByPTeamLeader').text();
	var d=$('#tbUserDeptByPImplementPlan').text();
	var e=$('#tbUserDeptByPAssistDept').text();
	var houe=$("input[type='radio']:checked").val();
	var EId = getCookie(eventId);
    var url = 'work2/LZMReport_directly.action';
    var params = {
		'proposeRecord.c': '8',
		//'proposeRecord.tbUserByPrCheckId.UId': rr,
        'proposeRecord.PViceCommander': b,
        'proposeRecord.PTeamLeader': c,
        'proposeRecord.PCommander': a,
		'proposes.tbEvent.EId': EId,
        'proposes.ppId': ppId,
		//下面是部门
		'proposeRecord.PImplementPlan': d,
		'proposeRecord.PAssistDept': e,
		//下面是呈批记录
		'proposeRecord.PComments': $('#PComments').attr('value'),
		//下面是预案等级建议
		'proposeRecord.e':houe,
		//下面是附件
		'proposeRecord.f':$('#planb').val(),
		'proposeRecord.g':$('#pland').val()
    };
    jQuery.post(url, params, directlyRst, 'json');
}

/**
 * 作增加呈批回调函数
 */
function directlyRst(data){
    if (data.ajaxRst == "success") {
		//alert("directlyRst");
        //window.location.href = "reportTable.jsp?reportTag=succ";
		//window.location.href="/ag/work/zhzrmnoplan.jsp";
		window.location.href="/ag/work/operate_rst_noplan.jsp";
    }
    else {
        alert("服务器异常！");
    }
}

/**
 * 作增加呈批
 */
function agreeLower(rr){
	rr.attr('disabled',"true");
    var url = 'work2/LZMReport_agreeLower.action';
	var timestamp = Date.parse(new Date());
    var params = {
        'timestamp': timestamp,
		'proposeRecord.PComments': $('#PComments').attr('value'),
		//'proposes.c': '7',
		'proposeRecord.c': '7',
		'proposes.ppId': ppId
    };
    jQuery.post(url, params, agreeLowerRst, 'json');
}

/**
 * 作增加呈批回调函数
 */
function agreeLowerRst(data){
    if (data.ajaxRst == "success") {
        window.location.href = "reportTable.jsp?reportTag=succ";
    }
    else {
        alert("失败，请重试！");
    }
}

     /*
	 * 存储到正式 的呈批表
	 */
	function saveToFomalPropose1(){
		var a=$('#tbUserByPCommander1').text();
		//alert(a);
		var b=$('#tbUserByPViceCommander1').text();
		var c=$('#tbUserByPTeamLeader1').text();
		var d=$('#tbUserDeptByPImplementPlan').text();
		var e=$('#tbUserDeptByPAssistDept1').text();
		
		
		//alert("the same");
		saveAdmin1(a,b,c,d,e);
		//alert(a+" "+b+" "+c+" "+d+" "+e);
	}
	
function saveAdmin1(a,b,c,d,e){
	//alert("gggg454545");
	//alert(b);	
    var EId = getCookie(eventId);
    var url = 'work2/LZMReport_saveAdmin.action';
    var params = {
        'proposes.tbUserByPViceCommander.UId': b,
        'proposes.tbUserByPTeamLeader.UId': c,
        'proposes.tbUserByPCommander.UId': a,
        'proposes.tbEvent.EId': EId,
		//下面是部门
		'proposes.e': d,
		'proposes.tbUserDeptByPAssistDept.udId': e
    };
    jQuery.post(url, params, saveAdminRstZRT1, 'json');
}
/**
 * 作增加呈批回调函数
 */
function saveAdminRstZRT1(data){
	if (data.ajaxRst == "success") {
		//alert("OK");
		window.location.href="/ag/work/zhzrmnoplan.jsp";
		//window.location.href="reportTable.jsp?reportTag=succ";
		//checkEmergency();
		//setEventPlan2SessionNoPlan();
		//setCookie(BACK_URL,"event_query_start.jsp")
		//window.location.href="operate_succ.jsp";
		//window.location.href="/ag/work/operate_rst_noplan.jsp";
	}else{
		alert("失败，请重试！");
	}	
}
/*
 * 选择预案等级
 * @memberOf {TypeName} 
 */
function selectPlanLevel(){
    	//alert("cool");
    	$('[name=planRadio]').click(function(){
    		var planlevelId=$(this).attr('id');
//    			alert(planlevelId);
    			
//    			window.open("/ag/work/setPlanStandard.jsp?planLevel="+$(this).attr('value'), null,
//									"scrollbars = yes,resizable = yes");
    			//以下为通过plan的等级来判断,由于锐童原来为one,two,three,four,现在要的参数为1,2,3,4
    			var planLevel='1';
    			switch(planlevelId){
    			case 'one':planLevel='1';break;
    			case 'two':planLevel='2';break;
    			case 'three':planLevel='3';break;
    			case 'four':planLevel='4';break;
    			}
//    			alert(planLevel);
    			var url_updateEventLevel="/ag/dgm/updateEventLevel_DGMdisposalAdvice.action";
    			$.post(url_updateEventLevel,{'eventLevel':planLevel},function(data){					//更新事件等级的				
    			});
    			window.location.href="/ag/work/setPlanStandard.jsp?planLevel="+$(this).attr('value'), null,
			"scrollbars = yes,resizable = yes";
    	});
    }
/*
function findReportTableEnt(){	
	var timestamp = Date.parse(new Date());
	//$.get("/do/processStart_processEventStartByPlan.action?ts="+timestamp+"&eventId="+getCookie(eventId),null,setEventPlan2SessionRst);
}

function findReportTableEntRst(data){
	
}*/